

# set up the working directory in your computer
setwd("")

# change the language setting for display
Sys.setenv(LANG = "en")

# this google trends data are downloaded on 09/19/16. 
# from : https://www.google.com/trends/
# NOTE : trends data for following key words are collected based on google's categorized terms
# presidential debate, presidential election, George Bush, John Carry 

tdata <- read.csv("google_trends_0919.csv")

g.interest <- tdata[,2:8]
x.date <- as.Date(as.character(tdata$Day))


pdf("Figure1.pdf",paper="special",width=10,height=5)
layout(matrix(1:2,1,2))
plot(x.date,g.interest[,1],xlab="",ylab="Google Search Index", main="", xaxt="n",
	xlim=c(as.Date("2004-08-01"),as.Date("2004-12-30")),type="l",col="green",lty=1)

points(x.date,g.interest[,2],col="orange",type="l", lty=1)
points(x.date,g.interest[,3],col="red",type='l', lwd=2)
points(x.date,g.interest[,4],col="purple",type='l',lty=1)
points(x.date,g.interest[,5],col="pink",type='l',lty=1)
points(x.date,g.interest[,6],col="blue",type='l',lwd=2)
points(x.date,g.interest[,7],col="black",type='l',lty=1)

axis.Date(1, at=seq(min(x.date), max(x.date), by="15 day"), format="%b/%d",cex.axis=0.8)
legend("topright","A",bty="n",cex=2)

legend("topleft",c("hurricane","csi","presidential debate","flu","red sox","presidential election","turkey"),bty="n",
	lty=1, col=c("green","orange","red","purple","pink","blue","black"),cex=0.7)

plot(x.date,tdata[,9],xlab="",ylab="Google Search Index", main="", xaxt="n",
	xlim=c(as.Date("2004-08-01"),as.Date("2004-12-30")),type="l",col="red",lty=1,lwd=2)
points(x.date,tdata[,10],col="blue",type="l", lty=1,lwd=1)
axis.Date(1, at=seq(min(x.date), max(x.date), by="15 day"), format="%b/%d",cex.axis=0.8)

legend("topleft",c("George Bush","John Kerry"),bty="n",
	lty=c(1,1), col=c("red","blue"))
legend("topright","B",bty="n",cex=2)

dev.off()
